package com.example.springbootswagger.controller;

import com.example.springbootswagger.entity.UserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@Controller 视图解析器可以解析return 的jsp,html页面，并且跳转到相应页面，若返回json等内容到页面，则对应的方法需要加@ResponseBody注解
//@RestController 相当于@Controller+@ResponseBody的结合，返回json数据不需要在方法前面加@ResponseBody注解了，
//但使用@RestController这个注解，方法就不能返回jsp,html页面，视图解析器无法解析jsp,html页面。

@RestController
@RequestMapping("/api")
@Api(tags = "Hello接口")
public class HelloController {

    @RequestMapping(value = "/hello")
    @ApiOperation(value = "测试swagger")
    public String hello(@ApiParam(value = "入参") @RequestParam String username) {
        return username;
    }

    @RequestMapping(value = "/hello2")
    @ApiOperation(value = "测试swagger", response = UserInfo.class)
    public String hello2(@ApiParam(value = "入参") @RequestBody UserInfo userInfo) {
        return userInfo.toString();
    }

}
